#!/bin/bash
#export BUILD_ID=dontKillMe
#APP_NAME打包的文件名
APP_NAME=springboot_demo-1.0-SNAPSHOT.jar

#启动脚本中的jvm参数解释及配置参考https://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html
#  -Xms进程占用最小内存，一般应用建议在800m以上
#  -Xmx进程占用最大内存，一般应用建议在3000m以上，但不应该超过操作系统总内存的70%
#-Dspring.profiles.active=dev指定启动环境为dev环境，使用application.yml与application-dev.yml配置，若application-dev.yml和application.yml都有相同的属性，但是值不同，使用application-dev.yml的值
#/software/jdk1.8.0_221/bin/java一直指定到jdk安装路径下的bin路径下的java文件
#此处没有使用优雅停机方案，可参考https://www.jianshu.com/p/0c49eb23c627使用优雅停机方案
pids=`ps -ef |grep $APP_NAME |grep -v grep |awk '{print $2}'`
if [ -z $pids ]; then
     #kill -9 $pids

     #echo 'process exist,will be killed and restart'

     nohup /software/jdk1.8.0_221/bin/java -Dfile.encoding=utf-8 -Dspring.profiles.active=dev -jar  -server -Xms3072m -Xmx3072m -Xmn1280m -Xss256k -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=68 -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/scene/bin/logs/jvm -XX:ErrorFile=/home/scene/bin/logs/jvm/hs_err_pid%p.log -Xloggc:/home/scene/bin/logs/jvm/gc.log   $APP_NAME  >/home/scene/log/nohup.log 2>&1 &

     sleep 5s
  else
     #echo 'process not exist,begin to run'
     echo 'process exist,will be killed and restart'
      kill -9 $pids

      nohup /software/jdk1.8.0_221/bin/java  -Dfile.encoding=utf-8 -Dspring.profiles.active=dev -jar   -server -Xms3072m -Xmx3072m -Xmn1280m -Xss256k -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=68 -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/scene/bin/logs/jvm -XX:ErrorFile=/home/scene/bin/logs/jvm/hs_err_pid%p.log -Xloggc:/home/scene/bin/logs/jvm/gc.log  $APP_NAME  >/home/scene/log/nohup.log 2>&1 &

     sleep 5s
  fi